package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by windo on 16/7/13.
 */
public class CreateQuestionTask extends CouponHttpBaseTask {
    private String mSubjectNo;
    private int mRewardCount;
    private String mGrade;
    private String mViewType;
    private String mQuestionImages;
    private String mRightAnswer;
    private String mAnalyze;
    private String mQuestionType;
    private String mAnswerType;

    public CreateQuestionTask(String subjectNo, int rewardCount, String grade,
                              String viewType, String questionImages, String rightAnswer,
                              String analyze, String questionType, String answerType) {
        super();
        mSubjectNo = subjectNo;
        mRewardCount = rewardCount;
        mGrade = grade;
        mViewType = viewType;
        mQuestionImages = questionImages;
        mRightAnswer = rightAnswer;
        mAnalyze = analyze;
        mQuestionType = questionType;
        mAnswerType  = answerType;
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT){
            CouponHttpRequest request = new CouponHttpRequest();
            request.setApiNo(ApiNo.CREATE_QUESTION);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("subjectNo",mSubjectNo);
            jsonObject.put("rewardCount",mRewardCount);
            jsonObject.put("grade",mGrade);
            jsonObject.put("viewType",mViewType);
            jsonObject.put("questionImage",mQuestionImages);
            jsonObject.put("rightAnswer",mRightAnswer);
            jsonObject.put("analyze",mAnalyze);
            jsonObject.put("questionType",mQuestionType);
            jsonObject.put("answerType",mAnswerType);
            request.setData(jsonObject.toString());
            addRequest(request);

        }
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        notifyTaskCompleted(TaskResultCode.SUCCESS, null);
    }
}
